package {{{ .TableName }}}

import (
	"github.com/gin-gonic/gin"
	"likeadmin/admin/schemas/req"
	"likeadmin/admin/service/system"
	"likeadmin/core"
	"likeadmin/core/request"
	"likeadmin/core/response"
	"likeadmin/middleware"
	"likeadmin/util"
)


func {{{ title (toCamelCase .ModuleName) }}}Route(rg *gin.RouterGroup) {
	db := core.GetDB()

	server := New{{{ title (toCamelCase .EntityName) }}}Service(db)

	handle := productHandler{service: server}

	rg = rg.Group("/", middleware.TokenAuth())
	rg.GET("/{{{ .ModuleName }}}/list", handle.List)
	rg.GET("/{{{ .ModuleName }}}/detail", handle.Detail)
	rg.POST("/{{{ .ModuleName }}}/add", handle.Add)
	rg.POST("/{{{ .ModuleName }}}/edit", handle.Edit)
	rg.POST("/{{{ .ModuleName }}}/del", handle.Del)
}
type {{{ toCamelCase .ModuleName }}}Handler struct {
	service I{{{ title (toCamelCase .EntityName) }}}Service
}

//list {{{ .ModuleName }}}列表
func (hd {{{ toCamelCase .ModuleName }}}Handler) List(c *gin.Context) {
	var page request.PageReq
	var listReq {{{ title (toCamelCase .EntityName) }}}ListReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
		return
	}
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
		return
	}
	res, err := hd.service.List(page, listReq)
	response.CheckAndRespWithData(c, res, err)
}

//detail {{{ .ModuleName }}}详情
func (hd {{{ toCamelCase .ModuleName }}}Handler) Detail(c *gin.Context) {
	var detailReq {{{ title (toCamelCase .EntityName) }}}DetailReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
		return
	}
	res, err := hd.service.Detail(detailReq.{{{ title (toCamelCase .PrimaryKey) }}})
	response.CheckAndRespWithData(c, res, err)
}

//add {{{ .ModuleName }}}新增
func (hd {{{ toCamelCase .ModuleName }}}Handler) Add(c *gin.Context) {
	var addReq {{{ title (toCamelCase .EntityName) }}}AddReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
		return
	}
	response.CheckAndResp(c, hd.service.Add(addReq))
}

//edit {{{ .ModuleName }}}编辑
func (hd {{{ toCamelCase .ModuleName }}}Handler) Edit(c *gin.Context) {
	var editReq {{{ title (toCamelCase .EntityName) }}}EditReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
		return
	}
	response.CheckAndResp(c, hd.service.Edit(editReq))
}

//del {{{ .ModuleName }}}删除
func (hd {{{ toCamelCase .ModuleName }}}Handler) Del(c *gin.Context) {
	var delReq {{{ title (toCamelCase .EntityName) }}}DelReq
	if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
		return
	}
	response.CheckAndResp(c, hd.service.Del(delReq.{{{ title (toCamelCase .PrimaryKey) }}}))
}
